limsBatchRevise.editPage = {

    getGridParam : function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-batch-revise-edit-list-grid',
            url : limsBatchRevise.baseUrl + '/queries/raw',
            requestData : {
                // status_SB : 'draft',
                createdById_EQ: workspace.user.id,
            },
            service : 'limsBatchReviseServiceImpl',
            dbTable : 'T_LIMS_BATCH_REVISE',
            columns : limsBatchRevise.getEditListColumns(),
            deleteFormatter: function (row) {
                return row.batchCode || row.id;
            },
            onCellClick : function(field, row) {
                field === 'batchCode' && _this.loadDetailPage(row);
            },
            page: true,
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick: function () {
                    Gikam.preInsert({
                        modalTitle: 'GIKAM.BUTTON.INSERT',
                        fields: limsBatchRevise.getBaseInfoFormFields(),
                        url: limsBatchRevise.baseUrl,
                        param: {
                            type: 'temp'
                        }
                    }).done(function (id) {
                        var row = {}
                        let url = Gikam.printf(limsBatchRevise.baseUrl + '/{id}', {id: id})
                        Gikam.getTextSync(url).done(data => {
                            row = JSON.parse(data)
                        })
                        if (row.id) {
                            _this.loadDetailPage(row)
                        }
                        Gikam.getComp('lims-batch-revise-edit-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove-row',
                onClick : function() {
                    Gikam.getComp('lims-batch-revise-edit-list-grid').deleteRows(limsBatchRevise.baseUrl);
                }
            }, /*{
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.SUBMIT',
                icon: 'submit',
                onClick: function () {
                    var selections = Gikam.getComp('lims-batch-revise-edit-list-grid').getSelections();
                    if (Gikam.isEmpty(selections)) {
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                        return;
                    }
                    var submitUrl = limsBatchRevise.baseUrl + '/submit';
                    Gikam.confirm('GIKAM.MODAL.SUBMIT', 'GIKAM.TIP.SUBMIT', function () {
                        workspace.window.showMask()
                        Gikam.postText(submitUrl, Gikam.getJsonWrapper(null, [null, selections])).done(function () {
                            Gikam.getComp('lims-batch-revise-edit-list-grid').refresh();
                        }).always(function () {
                            workspace.window.closeMask()
                        })
                    })
                }
            }*/{// 换成工作流
                type: 'button',
                text: 'GIKAM.WORKFLOW.BUTTON.SUBMIT',
                icon: 'batch-submit',
                color: 'success',
                onClick : function() {
                    _this.submit();
                }
            }, ]
        }
    },

    submit : function() {
        var grid = Gikam.getComp('lims-batch-revise-edit-list-grid');
        Gikam.create('workflow').submit({
            data : grid.getSelections(),
            pageObject : limsBatchRevise,
            formatterToolbar: (toolbar, type, formId) => {
                toolbar.forEach(b => {
                    if (b.text === 'GIKAM.BUTTON.CONFIRM') {
                        b.class = 'blue'
                        b.icon = 'save'
                        b.color = 'white'
                    } else if (b.text === 'GIKAM.BUTTON.CANCEL') {
                        b.icon = 'back'
                    }
                })
                return toolbar
            }
        }).done(function() {
            grid.refresh();
        });
    },

    loadDetailPage : function(row) {
        workspace.window.load(limsBatchRevise.baseUrl + '/page/detail' + Gikam.param({
            id : row.id,
            batchId : row.batchId,
            reviseType : row.reviseType,
            processStatus: row.processStatus
        }));
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-batch-revise-edit-list-layout',
            renderTo : workspace.window.$dom,
            center : {
                items : [ this.getGridParam() ]
            }
        });
    },

    init : function() {
        this.create();
    }
};
